#include <ros/ros.h>
#include <geometry_msgs/Twist.h>

//订阅turtle1/cmd_vel话题 获得发往这个话题的消息 修改消息内容后 发往话题turtle1/cmd_vel_reversed（使海龟订阅这个话题即可反转控制海龟）

ros::Publisher *pubPtr;

void commandVelocityRecevied(const geometry_msgs::Twist& msgIn){
	geometry_msgs::Twist msgOut;
	msgOut.linear.x = -msgIn.linear.x;
	msgOut.angular.z = -msgIn.angular.z;

	pubPtr->publish(msgOut);
}

int main(int argc, char **argv){
	ros::init(argc, argv,"reverse_velocity");
	ros::NodeHandle nh;

	pubPtr = new ros::Publisher(nh.advertise<geometry_msgs::Twist>("turtle1/cmd_vel_reversed",1000));

	ros::Subscriber sub = nh.subscribe("turtle1/cmd_vel",1000,&commandVelocityRecevied);

	ros::spin();

	delete pubPtr;
}
